import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
import { relations } from "drizzle-orm";
import { auditSchema } from "./audit";
import * as userSessions from "./userSessions";
import * as drivers from "./drivers";
import * as feeds from "./feeds";
import * as links from "./links";
export const tableName = "users";

export const route = "users";

export const definition = {
	id: text("id").primaryKey(),
	username: text("username"),
	email: text("email"),
	email_verified: integer("email_verified").default(0), // 0 or 1
  phone: text("phone"),
	phone_verified: integer("phone_verified").default(0), // 0 or 1
	password_hash: text("password_hash"),
	push_wx: text("push_wx"),
	push_tg: text("push_tg"),
	push_web: text("push_web"),
	role: text("role").$type<"admin" | "editor" | "user">().default('user'),
	plan: text("plan").$type<"normal" | "pro" | "supper">().default('normal'),
};

export const table = sqliteTable(tableName, {
	...definition,
	...auditSchema,
});

export const relation = relations(table, ({ many }) => ({
	sessions: many(userSessions.table),
	drivers: many(drivers.table),
	feeds: many(feeds.table),
	links: many(links.table),
}));
